package org.example.designpatterns.singleton.demo3;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author Gong.Yang
 * readResolve（）解决读写破坏单例
 */
public class Singleton implements Serializable {
    private Singleton() {
    }

    private static final Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    /**
     * 下面是为了解决序列化反序列化破解单例模式
     */
    @Serial
    private Object readResolve() {
        return instance;
    }
}
